package com.ftg.learn.util;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * 数据控制层响应数据封装类
 *
 * @author 布衣
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class PageUtil<E> {

    private Integer code;

    private String msg;

    //如果data为null,我们应该不转换成json
    private E data;

    public static <E> PageUtil<E> success(E data) {
        return new PageUtil<>(200, "success", data);
    }

    public static <E> PageUtil<E> success(R msg, E data) {
        return new PageUtil<>(200, msg.getMsg(), data);
    }

    public static <E> PageUtil<E> fail(R msg) {
        return new PageUtil<>(500, msg.getMsg(), null);
    }

    public static <E> PageUtil<E> fail(Integer code, R msg) {
        return new PageUtil<>(code, msg.getMsg(), null);
    }

}
